include<BOSL2/std.scad>
include<BOSL2/gears.scad>
include<tools/util.scad>
$fn=100;

mod=1.5; //模数
 backing=3; //冠齿轮齿下圆盘厚度
 PA=20;//压力角
 face=5;//厚度
 
 cteeth=60; //齿数
pteeth=15;//齿数
dteeth=75;
//frame();
//moto_gear();
//crown_and_bearing();

cpr = pitch_radius(mod=mod, teeth=cteeth);
ppr = pitch_radius(mod=mod, teeth=pteeth);
dpr = pitch_radius(mod=mod, teeth=dteeth);

module moto_gear(){
    translate([0,-(cpr+face/2),ppr+backing+face/2]){
    spur_gear(mod=mod, teeth=pteeth,pressure_angle=PA, thickness=face,orient=BACK, gear_spin=180/pteeth,profile_shift=0);
    rotate([90,0,0])difference(){
            cylinder(h=20,d=12);
            translate([0,0,17])moto_axis_mask();
            }

    }
}
module crown_and_bearing(){

    translate([0,0,backing+1.25*mod])//齿根高
    crown_gear(mod=mod, teeth=cteeth, backing=backing,face_width=face, pressure_angle=PA);

   
    translate([0,0,-8])d_bearing(r=30,height=15,ball_r=6,ball_num=8);
    translate([0,0,-1])cylinder(h=1,d=60);  
}  
//1小
 cylinder(h=backing+face+2*ppr+5,d=12);
translate([0,0,backing+face+2*ppr+5]){
spur_gear(mod=mod, teeth=pteeth,pressure_angle=PA, thickness=face);

cylinder(h=5,d=17);
translate([0,0,12.5])d_bearing(r=30,height=15,ball_r=6,ball_num=8);
translate([0,0,12])cube([12,12,14.5],center=true);
translate([0,0,20])cylinder(h=6,d=60);

//1大        
translate([ppr+dpr,0,0]){spur_gear(mod=mod, teeth=dteeth,pressure_angle=PA, thickness=face,gear_spin=180/dteeth);
cylinder(h=30+face,d=12);

//2小
translate([0,0,face+20])spur_gear(mod=mod, teeth=pteeth,pressure_angle=PA, thickness=face);
}
//2大
translate([0,0,face+20]){
        spur_gear(mod=mod, teeth=dteeth,pressure_angle=PA, thickness=face,gear_spin=180/dteeth);
       union(){
        hull(){
                cylinder(h=10,d=16);
                translate([0,0,15])cube([12,12,10],center=true);
            }
            translate([0,0,24])cube([12,12,10],center=true);
        }
    }
}
 translate([ppr+dpr,0,-28.5])cylinder(h=62,d=12);
//
module frame(){
   
    translate([35,0,-30])cube([190,80,3],center=true);  
    difference(){
        translate([35,0,67])cube([190,30,3],center=true); 
        translate([ppr+dpr,0,65.5])#cylinder(h=3.1,d=12.2);
        translate([0,0,65.5])#cylinder(h=3.1,d=16.2);
    }
    translate([127,-15,-28.5])cube([3,30,94]);   
/////
    translate([0,0,-12])cube([12,12,20],center=true); 
    translate([0,0,-30])cylinder(h=10,d=20);  

///
    translate([ppr+dpr,0,-28])difference(){
        cylinder(h=40,d=16);
        cylinder(h=40,d=11.7);
    }

}
module moto_axis_mask(){
intersection(){
            cube([5.6,3.9,6.1],center=true);
            translate([0,0,-3])cylinder(h=6.1,d=5.6);
        }
}  